package com.gxa.controller.dmt.user;


import com.gxa.common.R;
import com.gxa.entity.SysJob;
import com.gxa.service.SysJobService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("/userManagement/job")
@Api(value = "职位管理测试",tags = "职位管理接口API")
@RequiresRoles(value = {"超级管理员"},logical = Logical.OR)
public class SysJobController {

    @Autowired
    SysJobService service;


    /**
     * 分页显示所有职位信息
     * @param currentPage 当前页码数默认第一页
     * @param pageSize 每页显示记录数
     * @return R
     */
    @ApiOperation(value = "显示所有职位信息",notes = "显示所有职位信息",
            httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @RequestMapping(value = "/findJobList",method = RequestMethod.GET)
    @ResponseBody
    public R findJobList(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize")Integer pageSize ){
        return service.selectAllJob(currentPage,pageSize);
    }


    /**
     * 添加职位信息
     * @param sysJob 职位实体
     * @return R
     */
    @ApiOperation(value = "添加职位信息",notes = "添加职位",
            httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @RequestMapping(value = "/addJob",method = RequestMethod.POST)
    @ResponseBody
    public R addJob(@RequestBody @ApiParam(name = "sysJob",value = "职位实体",required = true) SysJob sysJob){
        return service.addJob(sysJob);
    }


    /**
     * 模糊查询职位信息列表
     * @param currentPage 当前页码数默认第一页
     * @param pageSize 每页显示记录数
     * @param title 职位名称
     * @return R
     */
    @ApiOperation(value = "模糊查询职位信息列表",notes = "模糊查询职位信息列表",
            httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "title",value = "职位名称",paramType = "query",dataType = "String",required = true)
    })
    @RequestMapping(value = "/showJobByTitle",method = RequestMethod.GET)
    @ResponseBody
    public R showJobByTitle(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize")Integer pageSize ,@RequestParam("title")String title){
        return service.selectJobByTitle(title,currentPage,pageSize);
    }



    /**
     * 根据职位ID修改职位信息
     * @param sysJob 部门实体（前端传一个json）
     * @return R
     */
    @ApiOperation(value = "根据职位ID修改职位信息",notes = "根据职位ID修改职位信息",
            httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @RequestMapping(value = "/updateJobById",method = RequestMethod.POST)
    @ResponseBody
    public R updateJobById(@RequestBody @ApiParam(name = "sysJob",value = "职位实体",required = true) SysJob sysJob){
        return service.updateJobById(sysJob);
    }


    /**
     * 根据职位Id回显职位信息
     * @param id 职位ID
     * @return R
     */
    @ApiOperation(value = "根据职位Id回显职位信息",notes = "根据职位Id回显职位信息",
            httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "职位ID",paramType = "query",dataType = "String",required = true)
    })
    @RequestMapping(value = "/showJobById",method = RequestMethod.GET)
    @ResponseBody
    public R showJobById( @RequestParam("id")Integer id){
        return service.selectJobById(id);
    }



    /**
     * 根据职位ID删除职位
     * @param id 职位ID
     * @return R
     */
    @ApiOperation(value = "根据职位ID删除职位",notes = "根据职位ID删除职位",
            httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "职位ID",paramType = "query",dataType = "String",required = true)
    })
    @RequestMapping(value = "/delJobById",method = RequestMethod.POST)
    @ResponseBody
    public R delJobById( @RequestParam("id")Integer id){
        return service.delJobById(id);
    }




}
